#ifndef __I_SOCKET_H_INCLUDED__
#define __I_SOCKET_H_INCLUDED__

#include "irrString.h"
#include "irrTypes.h"
#include "IUnknown.h"
//using namespace irr;
namespace game
{
	namespace net
	{
		//! Socket error codes
		enum E_SOCK_ERROR_CODES
		{
			//! No error
			IRR_NO_ERROR = 0,

			//! WiFi was not initialized
			WIFI_NOT_CONNECTED = 0xFFFFFFF0,

			//! This error occours when the method connectTo is called
			//! on an already connected socket
			INVALID_SOCKET_STATE = 0xFFFFFFF1,

			//! Cannot resolve hostname
			CANNOT_RESOLVE_HOSTNAME = 0xFFFFFFF2,

			//! Connection rejected
			CONNECTION_REJECTED = 0xFFFFFFF3,

			//! Unknown error
			UNKNOWN_ERROR = 0xFFFFFFF4

		};

		//! Interface of the socket class
		class ISocket : public irr::IUnknown
		{

		public:
			
			virtual ~ISocket()
			{
			}

			//! Connect the socket
			/** \param HostName: hostname or ip address to connect to, if this param is ommitted the socket will not be connected
			\param Port: the port number
			If the socket succesfully connects to the hostname specified the event onConnect is raised, otherwise
			an event onError will be raised.
			*/
			virtual void connectTo(c8* HostName, int Port) = 0;

			//! Returns the current error code
			virtual E_SOCK_ERROR_CODES getError() = 0;

			//! Close the current connection
			virtual void closeSocket() = 0;

			//! Send data
			//! \param data: a null-terminated string
			virtual void write(c8* data) = 0;

			//! Write line
			//! \param data: a string
			virtual void writeLine(c8* data) = 0;

			//! Write binary data
			//! \param data: a pointer to the buffer that has to be sent
			//! \param size: the size of the buffer in bytes
			virtual void writeBytes(c8* data, int size) = 0;

			//! Write binary string
			//! \param data: a binary string
			virtual void writeBytes(irr::core::stringb& data) = 0;

			//! Write binary string
			//! \param data: pointer to a binary string
			virtual void writeBytes(irr::core::stringb* data) = 0;			

			//! Gets received data
			//! \param buffer: The buffer where put the received data
			virtual bool getData(irr::core::stringb* buffer) = 0;

			//! Read line
			//! \param buffer: The buffer where put the read line
			virtual bool readLine(irr::core::stringc* buffer) = 0;

			//! Returns true if the socket is connected
			virtual bool isConnected() = 0;

			//! Gets socket id
			virtual int getSocketId() = 0;

			//! Gets the socket index in the cache
			virtual int getIndex() = 0;

			//! Returns the remote host ip
			virtual irr::core::stringc& getRemoteIP() = 0;

			//! Returns the remote host name
			virtual irr::core::stringc& getRemoteHost() = 0;

		};
	}
}
#endif